package com.rose.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.rose.mall.product.vo.AttrRespVo;
import com.rose.mall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.rose.mall.product.service.AttrService;
import com.rose.common.utils.PageUtils;
import com.rose.common.utils.R;



/**
 * 商品属性
 *
 * @author rose
 * @email 1942951600@qq.com
 * @date 2021-06-10 15:38:01
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    /**
     *  /base/list/{catelogId}  /sale/list/{catelogId}
     * @param catelogId
     * @param params
     * @return
     */
    @RequestMapping("/{attrType}/list/{catelogId}")
    public R baseAttr(@PathVariable("catelogId") Long catelogId,
                      @PathVariable("attrType") String type,
                      @RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params,catelogId,type);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
//    @RequestMapping("/list")
//    public R list(@RequestParam Map<String, Object> params){
//
//        PageUtils page = attrService.queryPage(params, catelogId);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息 todo  目前这个controller是不能用的
     */

    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
        //
//		AttrEntity attr = attrService.getById(attrId);
        AttrRespVo respVo = attrService.getAttrInfo(attrId);

        return R.ok().put("data", respVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
//		attrService.save(attr);

        attrService.saveAttr(attr);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attrVo){
//		attrService.updateById(attr);
        attrService.updateAttr(attrVo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("${moduleNamez}:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
